package com.sykj.springboot;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class BioServer {




    public static void main(String[] args) {
        try {
            System.out.println("=====服务端启动======");
            // 1.定义一个ServerSocket对象进行服务端的端口注册
            ServerSocket socket = new ServerSocket(9999);
            // 2.监听客户端的Socket连接请求
            Socket accept = socket.accept();
            // 3.从Socket管道中得到一个字节输入流对象
            InputStream is = accept.getInputStream();
            // 4.把字节输入流包装成一个缓冲字符输入流
            BufferedReader bf = new BufferedReader(new InputStreamReader(is));
            String msg = null;
            while ((msg = bf.readLine())!=null){
                System.out.println("服务端接收到:" + msg);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
